![]() ![]() |
Q: I'm writing a library to be used by many applications
and I need to yield time to other processes while waiting
for a lengthy network operation. If I call
A: You cannot defer suspend and resume events. You must handle them as the Process Manager gives them to you, or not at all. As a library developer, you have the following options for yielding time. CallbackThe best approach is for your library to make a callback
to the host application whenever it wants to yield time.
The host application can then yield using a mechanism that's
appropriate for its environment. For example, it might call
This approach has the advantage that it results in the simplest code for you, the library developer. The primary disadvantage is that it's possible for the host application to call your library again from within the yield callback. If your library is not prepared for this sort of reentrancy you must guard against it (or at least explicitly outlaw it in your documentation). Modal DialogsIf a callback is not possible, the only other correct solution is for your library to display a modal dialog while it is yielding time. A movable modal dialog is not sufficient -- the dialog must be system modal! The presence of the modal dialog will prevent the Process Manager from switching the host application to the background, and hence prevent the generation of suspend events. This approach has an obvious problem: it results in a bad user experience. It also has a more subtle problem: an unexpected modal dialog in the application's layer can cause pending update perils. Ostrich AlgorithmAn incorrect but expedient approach is to simply call
To summarize, the best way of yielding time from a library when you're unsure of the host application's environment is to call back to the host application and let it do the yielding. |
Developer Documentation | Technical Notes | Development Kits | Sample Code |